import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
  {
    path: "/login",
    name: "Login",
    component: () => import("@/views/login.vue"),
  },
  {
    path: "/",
    redirect: "/dashboard",
    name: "Home",
    hidden: true,
    component: () => import("@/views/home"),
    children: [
      {
        path: "/dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard"),
      },
      {
        path: "/equipmentInfo",
        name: "EquipmentInfo",
        component: () => import("@/views/equipmentInfo"),
      },
    ],
  },
  { path: "/404", component: () => import("../views/notFound") },
  { path: "/:catchAll(.*)", redirect: "/404" },
];

const router = new VueRouter({
  routes,
});

// 暂时隐藏重定向到登录
// router.beforeEach((to, from, next) => {
//   if (!localStorage.getItem("TOKEN") && to.name !== "Login") {
//     next("/login");
//   } else {
//     next();
//   }
// });

export default router;
